package cn.com.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.com.biz.RegisterformBiz;
import cn.com.entity.Consumer;
import cn.com.entity.Doctor;
import cn.com.entity.Registerform;

import com.opensymphony.xwork2.ActionSupport;

public class RegisterformAction extends ActionSupport implements SessionAware{
	/**
	 * 
	 */
	
	private static final long serialVersionUID = 1L;
	private Map<String, Object> session	;
	private Registerform registerform;
	private RegisterformBiz registerformbiz;
	private String registerformmsg;
	private Consumer consumer;
	private Doctor doctor;
	public Doctor getDoctor() {
		return doctor;
	}
	public void setDoctor(Doctor doctor) {
		this.doctor = doctor;
	}
	public Consumer getConsumer() {
		return consumer;
	}
	public void setConsumer(Consumer consumer) {
		this.consumer = consumer;
	}
	public String getRegisterformmsg() {
		return registerformmsg;
	}
	public void setRegisterformmsg(String registerformmsg) {
		this.registerformmsg = registerformmsg;
	}
	public RegisterformBiz getRegisterformbiz() {
		return registerformbiz;
	}
	public void setRegisterformbiz(RegisterformBiz registerformbiz) {
		this.registerformbiz = registerformbiz;
	}
	public Registerform getRegisterform() {
		return registerform;
	}
	public void setRegisterform(Registerform registerform) {
		this.registerform = registerform;
	}
	public Map<String, Object> getSession() {
		return session;
	}
	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		session=arg0;
	}

	//添加挂号单的action
	public String addRegisterform(){
		@SuppressWarnings("resource")
		ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
		registerformbiz=(RegisterformBiz)ac.getBean("registerformbiz");
		boolean bool=registerformbiz.addRegisterform(registerform);
		if(bool){
			session.put("consumerregisterform", registerform);
			setRegisterformmsg("预约挂号成功");
			return SUCCESS;
		}
		else{
			setRegisterformmsg("预约挂号失败");
			return ERROR;
		}
		
	}
	//通过用户id号码查询挂号单
	public String selectRegisterformByConsumerid(){
		@SuppressWarnings("resource")
		ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
		registerformbiz=(RegisterformBiz)ac.getBean("registerformbiz");
		List<Registerform> registerformlist=registerformbiz.selectRegisterformByConsumerid(consumer);
		session.put("rfbyconsumeridlist", registerformlist);
		return SUCCESS;
	}
	//通过医生id查询挂号单
	public String selectRegisterformByDoctorid(){
		@SuppressWarnings("resource")
		ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
		registerformbiz=(RegisterformBiz)ac.getBean("registerformbiz");
		List<Registerform> registerformlist=registerformbiz.selectRegisterformByDoctorid(doctor);
		session.put("rfbydoctoridlist", registerformlist);
		return SUCCESS;
	}
	//查询所有挂号单
	public String selectallregisterform(){
		@SuppressWarnings("resource")
		ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
		registerformbiz=(RegisterformBiz)ac.getBean("registerformbiz");
		List<Registerform> registerformlist=registerformbiz.selectAllRegisterform();
		session.put("allregisterform", registerformlist);
		return SUCCESS;
	}
}
